package com.indusfo.spc.untlis;

import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;

/**
 * @author chenm
 * @create 2020-01-16 16:32
 */
public class InstantUtil {

    public static long getMinute(String date){
        //        Instant now = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8)); //东八区时间差
        Instant now = Instant.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
        String formated = formatter.format(now);
        TemporalAccessor temporalAccessor = formatter.parse(formated);
        Instant instantNow = Instant.from(temporalAccessor);
        TemporalAccessor set = formatter.parse(date);
        Instant instantSet = Instant.from(set);
        return ChronoUnit.MINUTES.between(instantSet,now);
    }
}
